import { ref } from 'vue';
import { GameKernel, EVENTS } from '../game';

const kernel = GameKernel.inst;

const state = ref(kernel.sceneModel.uiState);
const showBattleView = ref(false);

kernel.bus.on(EVENTS.SCENE_STATE_UPDATE, () => {
  state.value = kernel.sceneModel.uiState;
});
kernel.bus.on(EVENTS.GAME_LOADED, () => {
  state.value = kernel.sceneModel.uiState;
});

export function useScene() {
  state.value = kernel.sceneModel.uiState;

  function openBattleView() {
    showBattleView.value = true;
  }

  function closeBattleView() {
    showBattleView.value = false;
  }

  return { state, showBattleView, openBattleView, closeBattleView };
}
